﻿Imports System.Data.SqlClient


'This class holding connections related to sql server.
Public Class clsSqlConnection

    'Every database operation we want to open database connection before inserting/fething data.here our 'app.config' file  
    'keeping an encrypted connection with sql server.before database transaction, wre need to decrypt and open that connection
    '
    Public Function toOpen() As SqlConnection

        'This is a class contains functions for encrypt/decrypt our database connection.
        Dim utility As New AppsUtility.EncDec
        Dim sqlconnection As New SqlConnection(utility.toDecrypt(System.Configuration.ConfigurationManager.AppSettings("SQLString")).Replace("serps", CurrentDB))

        Try
            sqlconnection.Open()

        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical, "SERPS")
        End Try

        Return sqlconnection

    End Function


    Public Function SqlConInitialize() As SqlConnection

        'This is a class contains functions for encrypt/decrypt our database connection.
        Dim utility As New AppsUtility.EncDec
        Dim sqlconnection As New SqlConnection(utility.toDecrypt(System.Configuration.ConfigurationManager.AppSettings("SQLString")).Replace("serps", CurrentDB))

        Return sqlconnection

    End Function



    Public Function toClose() As SqlConnection
        Dim utility As New AppsUtility.EncDec
        Dim sqlconnection As New SqlConnection(utility.toDecrypt(System.Configuration.ConfigurationManager.AppSettings("SQLString")).Replace("serps", CurrentDB))

        Try
            sqlconnection.Close()

        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical, "SERPS")
        End Try

        Return sqlconnection

    End Function
End Class
